package com.qianfeng.shoon.pet.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by Shoon on 2015/9/23.
 */
public class Utils {
    public static final String APP_VERSIONCODE_KEY = "versionCode";
    public static final String APP_ISFIRST_KEY = "isFirst";

    public static boolean isFirst(Context context) {
        int versionCode = 1;
        SharedPreferences sp = context.getSharedPreferences(AppConfig.APP_SP_FIRSRT, Context.MODE_PRIVATE);
        versionCode = sp.getInt(APP_VERSIONCODE_KEY, 1);

        boolean isFirst = false;
        if (isFirst || getVersion(context) != versionCode) {
            sp.edit().putBoolean(APP_ISFIRST_KEY, false);
            sp.edit().putInt(APP_VERSIONCODE_KEY, getVersion(context));
            return true;
        }
        return false;
    }
    /*
      获取应用程度版本号
     */

    private static int getVersion(Context context) {
        int versionCode = 1;
        PackageManager manager = context.getPackageManager();
        try {
            PackageInfo info = manager.getPackageInfo(context.getPackageName(),0);
            versionCode = info.versionCode;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionCode;
    }
}
